

/**
 * https://leetcode.cn/problems/valid-parentheses/
 * 正确的括号有先进后出的特性，和stack的特性一致，所以可以通过stack解决
 * 
 * @param {string} s
 * @return {boolean}
 */
var isValid = function(s) {
    let stack=[];
    let symbol={'}':'{',']':'[',')':'('}
    for (let index = s.length-1; index >=0; index--) {
        const element = s[index];
        if(symbol[element]){
            stack.push(element)
        }else{
            const top=stack[stack.length-1];
            console.log(top,element,symbol[top],stack)
            if(element==symbol[top]){
                stack.pop();
            }else{
                stack.push(element)
            }
        }
        
    }
    console.log(stack)
    return stack.length?false:true;
};

console.log(isValid('((){)'))
console.log(isValid('([]{})'))